
package me.zhengjie.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.domain.AppMessageTo;
import me.zhengjie.service.AppMessageToService;
import me.zhengjie.service.dto.AppMessageToQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "接收消息管理")
@RequestMapping("/api/appMessageTo")
public class AppMessageToController {

    private final AppMessageToService appMessageToService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('appMessageTo:list')")
    public void exportAppMessageTo(HttpServletResponse response, AppMessageToQueryCriteria criteria) throws IOException {
        appMessageToService.download(appMessageToService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询接收消息")
    @ApiOperation("查询接收消息")
    @PreAuthorize("@el.check('appMessageTo:list')")
    public ResponseEntity<Object> queryAppMessageTo(AppMessageToQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(appMessageToService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增接收消息")
    @ApiOperation("新增接收消息")
    @PreAuthorize("@el.check('appMessageTo:add')")
    public ResponseEntity<Object> createAppMessageTo(@Validated @RequestBody AppMessageTo resources){
        return new ResponseEntity<>(appMessageToService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改接收消息")
    @ApiOperation("修改接收消息")
    @PreAuthorize("@el.check('appMessageTo:edit')")
    public ResponseEntity<Object> updateAppMessageTo(@Validated @RequestBody AppMessageTo resources){
        appMessageToService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除接收消息")
    @ApiOperation("删除接收消息")
    @PreAuthorize("@el.check('appMessageTo:del')")
    public ResponseEntity<Object> deleteAppMessageTo(@RequestBody Integer[] ids) {
        appMessageToService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}